from fastapi import APIRouter, Depends
from pydantic import parse_obj_as

from app.core.responses import Response
from app.schemas.conversations import MessageSM
from app.services.auth import get_current_user
from app.services.conversations import ConversationsServices

router = APIRouter()


@router.get('/conversations/{receiver_id}')
def get_message(receiver_id: int, user: str = Depends(get_current_user)):
    conversation = ConversationsServices.get_message(user.id, receiver_id)
    return parse_obj_as(list[MessageSM], conversation)
    # return Response.success({'result': conversation})


@router.get('/conversations')
def get_conversation(user: str = Depends(get_current_user)):
    conversation = ConversationsServices.get_conversations(user.id)
    return Response.success({'result': conversation})
